import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';

import { SkWebService } from '@service/skweb.service';

@Component({
  selector: 'app-allservicelog',
  templateUrl: './allservicelog.component.html',
  styles: []
})
export class AllservicelogComponent implements OnInit {
  public servicelogList: any[] = [];
  public dataTotal = 1;  // 数据总量
  public pageIndex = 1;  // 页码
  public pageSize = 10;  // 每页数量

  public loading = true; // 数据加载loading

  public queryStr;  // 模糊查询内容

  constructor(
    public msg: NzMessageService,
    private skWebService: SkWebService
  ) { }

  ngOnInit() {
    this.fetchServiceLogList();
  }

  // 获取日志数据
  public async fetchServiceLogList(reset: boolean = false) {
    if (reset) {
      this.pageIndex = 1;
      this.queryStr = null;
    }
    // 数据参数
    const options: any = {
      pageIndex: this.pageIndex,
      pageSize: this.pageSize
    };
    if (this.queryStr) {
      options.logContent = this.queryStr.trim();
    }
    this.loading = true;  // 数据加载loading
    const ret: any = await this.skWebService.fetchServiceLog(options); // 查询数据
    this.loading = false; // 关闭数据加载loading

    const { count, rows } = ret.data;
    this.dataTotal = count;  // 数据总数
    this.servicelogList = rows; // 数据
  }
}
